package com.fileshare.web.controller.index.api;

import com.fileshare.web.dto.Result;
import com.fileshare.web.service.AuthService;
import com.fileshare.web.service.LoginService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/login")
@ResponseBody
public class LoginApiController {

    @Resource
    private LoginService loginService;

    @Resource
    private AuthService authService;

    @PostMapping(value = "web")
    @ResponseBody
    public Result<String> doLogin(@RequestParam String username,
                                  @RequestParam String password,
                                  @RequestParam(required = false) String rememberMe,
                                  HttpServletRequest request) {
        if (loginService.webLogin(username, password, request)) {
            return Result.success().with("success");
        } else {
            return Result.failed().with("failed");
        }

    }
}
